#ifndef __ACCOUNT_HANDLER__
#define __ACCOUNT_HANDLER__

#include <set>
#include <cstdint>
#include <string>
#include "Singleton.h"
#include "RedisClient.h"
#include "def.h"

// const uint32_t MIN_ACCOUNT = 10000000;
// const uint32_t MAX_ACCOUNT = 100000000;
// const uint32 UID_BUCKET_COUNT = 50;  // 只使用8位账号
const uint32 UID_BUCKET_COUNT = 50+10;  // 使用8位+9位账号
// const uint32 UID_BUCKET_COUNT = 50+10+14;  // 使用8位+9位+10位(<max(int32))账号
// const uint32 UID_BUCKET_COUNT = 50+10+14+25;  // 使用8位+9位+10位账号
const uint32 UID_BUCKET[] = {
    // 8位50个分段
    10000000,11801520,13609215,15403481,17275100,19082361,20808823,22609172,
    24426591,26207721,28002251,29889234,31677193,33406448,35201023,37068013,38888261,40605810,42405460,
    44200112,46077289,47808912,49600235,51406781,53202239,55062391,56804681,58601184,60408123,62201136,
    64099342,65806734,67606459,69417438,71202341,73098010,74802084,76602581,78401605,80207129,82068251,
    83804960,85608130,87409618,89209581,91059810,92855810,94604962,96406831,98203970,100000000,     
    // 9位10个分段
    178978952,266431301,338842198,425005401,507546834,618867274,677106803,790122877,834277538,921661632,
    // 10位40个分段
    1002071720,1124888500,1200132402,1277495458,1375077056,1456285423,1541110105,1601319938,1689153847, 
    1797262256,1842280347,1955909026,2011910023, 2111202923, // 前面的范围小于int32最大值, 边界个数74
    2194826257,2297584395,2360898959,2435777079,
    2537550964,2636706909,2683725749,2803995631,2873183831,2946767271,3054906465,3123421459,3219091062,
    3281728397,3390653250,3455035676,3551100377,3631562176,3707103792,3780053736,3857608550,3949517844,
    4060714098,4128771060,4191513911,4294967295
    };
    
class CAccountHandler
{
public:
    CAccountHandler(){};
    virtual ~CAccountHandler(){};
public:
    static CAccountHandler* Instance()
	{
		return CSingleton<CAccountHandler>::Instance();
	}
    void Init();
    void CheckUidSet();
    uint32 GetNewUidFromRedis();
    
public:
	RedisClient* m_userinfoRedis;

private:
    std::int32_t m_useout_buckets[UID_BUCKET_COUNT] = {0};
};

#endif 